<?php
namespace app\admin\controller;

use app\admin\services\FrontMenuService;
use app\common\controller\Base;

class FrontMenu extends Base
{
    /**
     * @var FrontMenuService
     */
    protected $_service;

    protected function _setService()
    {
        $this->_service = new FrontMenuService();
    }

    public function getMenusByPId()
    {
        $pid = I('get.pid', 0, 'intval');
        $root = I('get.root', 0, 'intval');
        $rt = $this->_service->getMenusByParentId($pid);
        if ($root) {
            array_unshift($rt, array(
                'id' => 0,
                'text' => 'Root'
            ));
        }
        return $this->returnJson($rt);
    }
}